# coding: utf-8
'''
微博app
'''
from sqlalchemy import create_engine
from sqlalchemy import Column, Integer, String, DateTime, text, TIMESTAMP
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()

class TBType(Base):
    __tablename__ = 'tbtype'
    id = Column('id', Integer, primary_key=True)
    typeName = Column('typeName', String(32), nullable = False, unique = True)
    
    def __init__(self, typeName):
        self.typeName = typeName

    def __repr__(self):
        return "<TYPE(%d, %s)" % (self.id, self.typeName)

class TBProfile(Base):
    __tablename__ = 'tbprofile'

    uid = Column('uid', Integer, primary_key = True, autoincrement = False) # 需要完善
    # 设置后不可以修改
    tdomain = Column('tdomain', String(32), nullable = False, index = True, unique = True)
    #取个响亮的名字(中文、EN)，如：斯丢彼得
    tname = Column('tname', String(32), nullable = False, unique = True)
    #1 个人生活; 2 企业; 3 媒体(如平面杂志报纸)；4 组织(如学校、环保、爱滋);
    #5 产品(如iphone、QQ6)
    #6 专题主题(某部电影、某个会议、学术、竞选、奥运、亚运)
    #7 社区
    type = Column('type', Integer, nullable = False)
    # 个人简述
    mydesc = Column('mydesc', String(128), nullable = True)
    gmtCreate = Column('gmtCreate', TIMESTAMP, server_default = text('NOW()'))
    gmtModified = Column('gmtModified', TIMESTAMP)

    def __init__(self, uid, tdomain, type, tname, mydesc):
        self.uid = uid
        self.tdomain = tdomain
        self.type = type
        self.tname = tname
        self.mydesc = mydesc
        self.gmtModified = None

    def __repr__(self):
        return "<TB Config('%d, %s, %d, %s')" % (self.uid, self.tdomain, self.type, self.mydesc)

class Tblog(Base):
    __tablename__ = 'tblog'
    id = Column('id', Integer, primary_key = True)
    uid = Column('uid', Integer, nullable = False)
    content = Column('content', String(512), nullable = False) 
    gmtCreate = Column('gmtCreate', TIMESTAMP, server_default=text('NOW()'))

    def __init__(self, uid, content):
        self.uid = uid
        self.content = content

class TBfollow(Base):
    __tablename__ = 'tbfollow'
    uid = Column(Integer, primary_key = True, autoincrement = False)
    duid = Column(Integer, nullable = False, index = True)

    def __init__(self, uid, duid):
        self.uid = uid
        self.duid = duid

if __name__ == "__main__":
    import sys
    sys.path.append("..")
    from models_ds import engine
    metadata = Base.metadata
    metadata.create_all(engine)

